package cn.shenlong.front.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.shenlong.common.Page;
import cn.shenlong.portal.domain.Event;
import cn.shenlong.portal.domain.EventImg;
import cn.shenlong.portal.service.EventService;

@Controller
public class EventAct {
	private static final Logger log = LoggerFactory
			.getLogger(EventAct.class);
	
	@Autowired
	private EventService eventService;
	
	
	@RequestMapping(value = "/front/active", method = RequestMethod.GET)
	public String index(Integer order,Integer pageNumber, Integer pageSize,HttpServletRequest request, ModelMap model) {
		log.info("");
		Map<String,Object> parm = new HashMap<String,Object>();
		if (pageNumber == null) {
			pageNumber = 1;
		}
		if (pageSize == null) {
			pageSize = 3;
		}
		parm.put("eventStatus", 1); 
		
		if(order==null){
			order = 2;
		}else if(order==3){
			parm.put("isUp", 2);
		}else if(order==4){
			
		}else if(order==5){
			
		}
		
		
		parm.put("order", order);
		Page<Event> page = eventService.findPageByParm(parm, pageNumber, pageSize);
		model.put("page", page);
		parm = new HashMap<String,Object>();
		parm.put("isCases", 2);
		parm.put("eventStatus", 1);
		parm.put("order", 2);
		List<Event> list = eventService.findByList(parm, 20);
		model.put("list", list);
		parm = new HashMap<String,Object>();
		parm.put("eventStatus", 1);
		parm.put("order", 2);
		parm.put("isTop", 2);
		
		List<Event> top = eventService.findByList(parm, 3);
		model.put("top", top);
		model.put("order", order);
		return "/front/active";

	}
	
	
	@RequestMapping(value = "/front/activeshow", method = RequestMethod.GET)
	public String activeshow(Integer id,HttpServletRequest request, ModelMap model) {
		log.info("");
		Event event = eventService.findByPk(id);
		model.put("event", event);
		return "/front/activeshow";

	}
	@RequestMapping(value = "/front/activeshow1", method = RequestMethod.GET)
	public String activeshow1(Integer id,HttpServletRequest request, ModelMap model) {
		log.info("");
		Event event = eventService.findByPk(id);
		model.put("event", event);
		
		Map<String, Object> otherParm = new HashMap<String, Object>();
		otherParm.put("eventId", event.getId());
		
		List<EventImg> list = eventService.findImgs(otherParm, null);
		model.put("imglist", list);
		
		return "/front/activeshow1";

	}

}
